package event_handlers

import (
	"fmt"
	"go-ddd-ecommerce/internal/domain/events"
)

// InventoryAlertHandler 库存预警处理器
type InventoryAlertHandler struct {
	lowStockThreshold int
}

func NewInventoryAlertHandler(threshold int) *InventoryAlertHandler {
	return &InventoryAlertHandler{
		lowStockThreshold: threshold,
	}
}

func (h *InventoryAlertHandler) Handle(event events.DomainEvent) error {
	switch e := event.(type) {
	case *events.ProductStockUpdateEvent:
		if e.NewStock <= h.lowStockThreshold {
			fmt.Printf("⚠️  库存预警: 商品 %s 库存仅剩 %d, 请及时补货\n",
				e.ProductID, e.NewStock)
		}
		fmt.Printf("📊 库存更新: 商品 %s 减少 %d, 剩余库存: %d\n",
			e.ProductID, e.Quantity, e.NewStock)
		return nil
	default:
		return nil
	}
}
